package com.power.service.impl;

import com.power.common.Contants;
import com.power.dao.SovleQueryDao;
import com.power.dao.impl.SovleQueryDaoImpl;
import com.power.ov.ResultData;
import com.power.pojo.SovlePojo;
import com.power.service.SovleQueryService;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/10 11:03
 * Description:
 * Version: V1.0
 */
public class SovleQueryServiceImpl implements SovleQueryService {
    SovleQueryDao sovleQueryDao=new SovleQueryDaoImpl();
    @Override
    public ResultData sovleQueryAll(String page, String limit) throws SQLException {
        ResultData resultData=new ResultData();
        int newPage=Integer.parseInt(page);
        int newLimit=Integer.parseInt(limit);
        List<Map<String,Object>> list=sovleQueryDao.sovleQueryAll(newPage,newLimit);
        if (list.size()>0){
            int count=sovleQueryDao.sovleCount();
            for (Map map:list){
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                map.put("find_time",simpleDateFormat.format(map.get("find_time")));
                map.put("lssue_time",simpleDateFormat.format(map.get("lssue_time")));
                map.put("intact",map.get("intact").toString()+"%");
            }
            resultData.setCode(Contants.TABLE_CODE);
            resultData.setCount(count);
            resultData.setMsg("查询成功");
            resultData.setData(list);
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查询失败");
        }
        return resultData;
    }

    @Override
    public ResultData sovleQueryByAll(SovlePojo sovlePojo, int page, int limit) throws SQLException {
        ResultData resultData=new ResultData();
        List<Map<String,Object>> list=sovleQueryDao.sovleQueryByAll(sovlePojo,(page-1)*limit,limit);
        if (list.size()>0){
            int count=sovleQueryDao.sovleByAllCount(sovlePojo);
            for (Map map:list){
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                map.put("find_time",simpleDateFormat.format(map.get("find_time")));
                map.put("lssue_time",simpleDateFormat.format(map.get("lssue_time")));
                map.put("intact",map.get("intact").toString()+"%");
            }
            resultData.setCode(Contants.TABLE_CODE);
            resultData.setCount(count);
            resultData.setMsg("查询成功");
            resultData.setData(list);
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无数据");
        }
        return resultData;
    }
}
